package webday03;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DemoRequest extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println(request);
		
		String name=request.getParameter("name");
		System.out.println(name);
		
	}
	//post请求乱码
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {
		//传过来的name是乱码，因为浏览器传过来的中文字节，
		//tomcat使用了iso-8859-1，把字节变成了字符串
		request.setCharacterEncoding("utf-8");
		String name=request.getParameter("name");
		
		//把字节转换成字符串             中的十六进制字节表示
//		byte[] bytes= {(byte)0xe5,(byte)0xb5,(byte)0xa3};
//		String s=new String(bytes,"utf-8");
//		
//		System.out.println(s);
//		
//		//把乱码的字符串变回字节
//		String name2=new String(name.getBytes("iso-8859-1"),"utf-8");
//		System.out.println(name2);
		
		//一句话可以代替上面，但要在请求参数之前
		
		
		System.out.println(request.getParameter("name"));
		
	}
}
